<input type="text" id="email" placeholder="输入邮箱订阅泰亨最新资讯">
<input type="hidden" value="<?= $this->contactHash?>" id="hash">
<a id="subBtn" href="javascript:;">立即订阅</a>

<script>
    $(function () {
        $('#subBtn').click(function () {
            var email = trim($('#email').val());
            var isEmail = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
            if ((email) == '') {
                alert('请先填写邮箱!');
                $('#email').focus();
                return false;
            } else if (!isEmail.test(email)) {
                alert('请填写正确的邮箱!');
                $('#email').focus();
                return false;
            } else {
                $.post('/api/email', {hash: $('#hash').val(), email : email},
                    function (data) {
                        switch (data.errcode) {
                            case 0:
                                alert('感谢您的订阅!');
                                break;
                            default :
                                alert(data.errmsg);
                        }
                    },
                    'json');
            }

        });
        function trim(s){
            return s.replace(/(^\s*)|(\s*$)/g, "");
        }
    })
</script>

